import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import VitePluginOss from "vite-plugin-oss";

export default ({ mode, command }) => {
	const plugins = [vue(), vueJsx()];
	return defineConfig({
		plugins: plugins,
		build: {
			sourcemap: false,
		},
		resolve: {
			alias: {
				"~utils": "/src/utils/",
				"~/": "/src/",
				"~service": "/src/service/",
				"~components": "/src/components/",
				"~shared": "/src/utils/shared/",
			},
		},
		envDir: "./",
		// 设置打包路径
		// base: "/",
		// base: loadEnv(mode, process.cwd()).VITE_APP_PREFIX,
		// 设置打包路径 基础路径+一级路径+path https://land-web-test.oss-cn-hangzhou.aliyuncs.com/dev/portalBrowse
		base: loadEnv(mode, process.cwd()).VITE_APP_PREFIX,
		server: {
			// 设置服务启动端口号
			port: 80,
			open: true,
			hmr: { overlay: false },
			host: "0.0.0.0",
			cors: true,
			// 设置代理，根据我们项目实际情况配置
			proxy: {
				"/api": {
					target: loadEnv(mode, process.cwd()).VITE_APP_BASE_URL,
					changeOrigin: true,
					secure: false,
				},
			},
		},
		css: {
			preprocessorOptions: {
				less: {
					additionalData: `@import "${resolve(
						__dirname,
						"src/style/theme.less"
					)}";`,
					javascriptEnabled: true,
				},
			},
		},
	});
};
